/*
 *  CERunningString.h
 *  LID Library
 *
 *  Created by Alexander Trutchenko on 09/11/11.
 *  Copyright 2011 League of Independent Developers. All rights reserved.
 *
 */

#ifndef __CE_RunningString_h__
#define __CE_RunningString_h__

#include "cocos2dx_extentions/nodes/CENodeRGBA.h"
#include "cocos2dx_extentions/nodes/CENodeScissored.h"

#include <vector>

namespace cocosext {

/////////////////////////////////////////////////////
//
/** CERunningString 
* 
*/
/////////////////////////////////////////////////////

typedef vector<cocos2d::CCNode*> CENodeVector;
typedef CERecursiveRGBA<CENodeScissored<cocos2d::CCNode> > CEScissoredRGBARecursiveNode;

class CERunningString : public CEScissoredRGBARecursiveNode
{
private:
	bool _isMovingAction;

protected:
	cocos2d::CCNode* _scrollableArea;
	CENodeVector _itemsOrder;
	bool _isRunning;
	float _runningSpeed; //points per second
	unsigned int _pauseCounter;

protected:
	CERunningString(float runningSpeed): _isMovingAction(false), _scrollableArea(NULL), _isRunning(false), _runningSpeed(runningSpeed), _pauseCounter(0) {;}

    virtual bool init(cocos2d::CCNode* item, va_list args);

public:
    virtual ~CERunningString() {;}

    static CERunningString* node(float runningSpeed);
	static CERunningString* node(float runningSpeed, cocos2d::CCNode* item, ...);


public:
//Cocos2d interface
	virtual void setContentSize(const cocos2d::CCSize& contentSize);
	
//Main interface
	void startRunning();
	void stopRunning();
	void pause();
	void resume();
	const CENodeVector& items() const { return _itemsOrder; } //Return items in their order
	void addItem(cocos2d::CCNode* item);
	void insertItem(unsigned int orderIndex, cocos2d::CCNode* item);
	void removeItem(unsigned int orderIndex);

protected:
	void updateRunning();
	void addItemNode(cocos2d::CCNode* item);
	void updateScrollableAreaSize();
	void updateItemsPositions();
}; //CERunningString


}; // end namespace cocosext

#endif // __CE_RunningString_h__
